<!--
 * @Descripttion: 委托管理
 * @version:
 * @Author: 赵致喜
 * @Date: 2020-10-15 10:58:18
 * @LastEditors: 穆宏宇
 * @LastEditTime: 2020-11-12 17:55:10
-->
<template>
  <div>
    <div class="control-box">
      <!-- control 操作区 START -->
      <e-control :search-form-options="formOptions"
                 :search-label-width="searchLabelWidth"
                 @on-search="searchControlHandle"
                 @on-refresh="refreshControlHandle"
                 @change-height="changeControlHeight"></e-control>
      <!-- control 操作区 END -->
    </div>
    <div class="table-box">
      <!-- table 数据表格 START -->
      <e-table :data="tableData"
               :columns="columns"
               stripe
               border
               :maxHeight="tableMaxHeight"
               style="width: 100%"
               :current="orderStatePageData.current"
               :total="orderStatePageData.total"
               @page-size-change="orderChangePageSize"
               @page-current-change="orderChangePageCurrent">
<!--        <template slot-scope="{scope}" slot="orderName" style="width: 100%;">-->
<!--          <el-popover placement="top" trigger="hover" style="width: 100%;">-->
<!--            <div class="cell-content name-w">{{scope.row.orderName}}</div>-->
<!--            <p class="overflow" slot="reference">{{scope.row.orderName}}</p>-->
<!--          </el-popover>-->
<!--        </template>-->
        <template slot-scope="{scope}"
                  slot="operation">
          <el-tooltip content="管理委托"
                      placement="top">
            <el-button @click="editTableHandle(scope.row)"
                     type="primary"
                     size="mini"
                     plain><i class="iconfont iconweituo01"></i></el-button>
          </el-tooltip>
          <el-tooltip v-if="scope.row.orderState === 'A1006'"
                      content="详情"
                      placement="top">
            <el-button @click="detailsControlHandle(scope.row)"
                       type="warning"
                       size="mini"
                       plain><i class="iconfont iconxiangqing01"></i></el-button>
          </el-tooltip>
        </template>
      </e-table>
      <!-- table 数据表格 END -->
    </div>
    <!-- editDialog 管理委托 START -->
    <el-dialog title="委托管理"
               :visible.sync="editDialogShow"
               :close-on-click-modal="false"
               :close-on-press-escape="false"
               width="80%">
      <h4>过程记录</h4>
      <e-table :data="processRecordData"
               :columns="columns2"
               :pageShow="false"
               stripe
               border
               :maxHeight="tableMaxHeight"
               style="width: 100%">
        <template slot-scope="{scope}" slot="remark">
          <el-popover placement="top" trigger="hover">
            <div class="cell-content">{{scope.row.remark}}</div>
            <p class="overflow" slot="reference">{{scope.row.remark}}</p>
          </el-popover>
        </template>
      </e-table>
      <el-row style="margin-bottom:20px">
        <h4 class="borderB">项目基本信息</h4>
        <el-col :span="12"
                class="pd5 lineHeight20">
          <el-col :span="6"
                  class="text-right">委托名称：</el-col>
          <el-col :span="18">
            <template>
              <el-popover placement="top" trigger="hover">
                <div class="cell-content">{{orderStateData.orderName}}</div>
                <p class="overflow baseInfo-w" slot="reference">{{orderStateData.orderName}}</p>
              </el-popover>
            </template>
          </el-col>
        </el-col>
        <el-col :span="12"
                class="pd5 lineHeight20">
          <el-col :span="6"
                  class="text-right">要求到货时间：</el-col>
          <el-col :span="18">{{orderStateData.requireDate|formeTime}}至{{orderStateData.requireEndDate|formeTime}}</el-col>
        </el-col>
        <el-col :span="12"
                class="pd5 lineHeight20">
          <el-col :span="6"
                  class="text-right">要求到货地点：</el-col>
          <el-col :span="18">{{orderStateData.addressDetail}}</el-col>
        </el-col>
        <el-col :span="12"
                class="pd5 lineHeight20">
          <el-col :span="6"
                  class="text-right">签订合同单位：</el-col>
          <el-col :span="18">{{orderStateData.purchaseName}}</el-col>
        </el-col>
        <el-col :span="12"
                class="pd5 lineHeight20">
          <el-col :span="6"
                  class="text-right">委托状态：</el-col>
          <el-col :span="18">{{orderStateData.orderStateName}}
          </el-col>
        </el-col>
        <el-col :span="12"
                class="pd5 lineHeight20">
          <el-col :span="6"
                  class="text-right">联系人姓名：</el-col>
          <el-col :span="18">{{orderStateData.consignee}}</el-col>
        </el-col>
        <el-col :span="12"
                class="pd5 lineHeight20">
          <el-col :span="6"
                  class="text-right">保证金金额：</el-col>
          <el-col :span="18">{{orderStateData.pledgePrice}}</el-col>
        </el-col>
        <el-col :span="12"
                class="pd5 lineHeight20">
          <el-col :span="6"
                  class="text-right">联系人手机：</el-col>
          <el-col :span="18">{{orderStateData.phone}}</el-col>
        </el-col>
        <el-col :span="12"
                class="pd5 lineHeight20">
          <el-col :span="6"
                  class="text-right">总预算（元）：</el-col>
          <el-col :span="18">{{orderStateData.sumBudget}}</el-col>
        </el-col>
        <el-col :span="12"
                class="pd5 lineHeight20">
          <el-col :span="6"
                  class="text-right">委托附件：</el-col>
          <el-col :span="18">
            <el-button type="text"
                       style="padding: 0 !important;"
                       @click="clickHandlePreview(orderStateData.entrustDocument)">{{orderStateData.entrustDocument|formatFile}}
            </el-button>
          </el-col>
        </el-col>
        <el-col :span="12"
                class="pd5 lineHeight20">
          <el-col :span="6"
                  class="text-right">备注：</el-col>
          <el-col :span="18">
            <template>
              <el-popover placement="top" trigger="hover">
                <div class="cell-content baseInfo-w">{{orderStateData.orderRemark}}</div>
                <p class="overflow" slot="reference">{{orderStateData.orderRemark}}</p>
              </el-popover>
            </template>
          </el-col>
        </el-col>
      </el-row>
      <e-table :data="orderStateDetailsData"
               :columns="columns1"
               stripe
               :border="true"
               :maxHeight="tableMaxHeight"
               style="width: 100%"
               :pageShow="false"
               :current="detailsPageData.current"
               :total="detailsPageData.total"
               @page-size-change="detailsChangePageSize"
               @page-current-change="detailsChangePageCurrent">
        <template slot-scope="{scope}" slot="goodsName">
          <el-popover placement="top" trigger="hover">
            <div class="cell-content">{{scope.row.goodsName}}</div>
            <p class="overflow" slot="reference">{{scope.row.goodsName}}</p>
          </el-popover>
        </template>
        <template slot-scope="{scope}" slot="brandName">
          <el-popover placement="top" trigger="hover">
            <div class="cell-content">{{scope.row.brandName}}</div>
            <p class="overflow" slot="reference">{{scope.row.brandName}}</p>
          </el-popover>
        </template>
        <template slot-scope="{scope}" slot="remark">
          <el-popover placement="top" trigger="hover">
            <div class="cell-content">{{scope.row.remark}}</div>
            <p class="overflow" slot="reference">{{scope.row.remark}}</p>
          </el-popover>
        </template>
        <template slot-scope="{scope}" slot="demandDocument">
          <el-button type="text" @click="clickHandlePreview(scope.row.demandDocument)">{{scope.row.demandDocument|formatFile}}</el-button>
        </template>
      </e-table>
      <span v-if="this.orderStateData.orderState === 'A1003'"
            slot="footer"
            class="dialog-footer">
        <el-button type="success"
                   @click="createProjectHandle">受理委托并创建项目</el-button>
        <el-button type="danger"
                   @click="returnOrderHandle">退回</el-button>
      </span>
    </el-dialog>
    <!-- editDialog 管理委托 END -->
    <!-- editDialog 创建项目 START -->
    <el-dialog title="创建项目"
               :visible.sync="editDialogShow1"
               :close-on-click-modal="false"
               :close-on-press-escape="false"
               width="80%">
      <el-form ref="editForm"
               :model="formData"
               :rules="formRules"
               label-width="150px">
        <el-card class="box-card"
                 style="overflow: initial;">
          <el-form-item label="项目名称"
                        prop="projectName">
            <el-input v-model="formData.projectName"></el-input>
          </el-form-item>
          <!-- <el-form-item label="项目编号">
            AG2020-1-0004
            {{projectNo}}
          </el-form-item> -->
          <!-- <el-form-item label="询价显示信息"
                        prop="inquiry"> -->
          <div>
            <span style="width:150px; float:left; text-align:right;line-height:40px; padding-right:12px; box-sizing: border-box; color:#606266"><span style="color:#f00">*</span> 询价显示信息</span>
            <span style="float:left">
              <el-form-item label="询价预选显示控制"
                            prop="budget"
                            :required="false">
                <el-radio v-model="formData.budget"
                          label="Bid_Show_Control_001_1">显示预算</el-radio>
                <el-radio v-model="formData.budget"
                          label="Bid_Show_Control_001_2">不显示预算</el-radio>
              </el-form-item>
              <el-form-item label="询价者价格显示控制"
                            prop="price">
                <el-radio v-model="formData.price"
                          label="Bid_Show_Control_002_1">只能看到自己的价格</el-radio>
                <el-radio v-model="formData.price"
                          label="Bid_Show_Control_002_2">可以看到询价者价格</el-radio>
              </el-form-item>
              <el-form-item label="竞拍模式"
                            prop="pattern">
                <el-radio v-model="formData.pattern"
                          label="Bid_Show_Control_003_1">正拍（升价竞拍）</el-radio>
                <el-radio v-model="formData.pattern"
                          label="Bid_Show_Control_003_2">反拍（降价竞拍）</el-radio>
              </el-form-item>
              <el-form-item label="报价次数控制"
                            prop="bidNumber">
                <el-input-number controls-position="right"
                                 :min="0"
                                 :max="1000000000000"
                                 :precision="0"
                                 v-model="formData.bidNumber"
                                 style="margin-right:20px"></el-input-number>
                <span style="color:#f00">(0为不限制供应商报价次数)</span>
              </el-form-item>
            </span>
            <div style="clear:both"></div>
          </div>
          <!-- </el-form-item> -->
          <el-form-item label="报名截止日期"
                        prop="endEnterTime">
            <el-date-picker v-model="formData.endEnterTime"
                            type="datetime"
                            :picker-options="pickerOptions"
                            placeholder="选择日期时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="询价时间"
                        prop="time">
            <el-date-picker v-model="formData.time"
                            type="datetimerange"
                            :picker-options="pickerOptions"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="项目说明" prop="projectRemark">
            <el-input type="textarea"
                      show-word-limit
                      maxlength="1000"
                      v-model="formData.projectRemark"></el-input>
          </el-form-item>
          <el-form-item label="参加供应商最低家数"
                        prop="bidMinNumber">
            <el-input-number controls-position="right"
                             :min="1"
                             :max="1000000000000"
                             :precision="0"
                             v-model="formData.bidMinNumber"></el-input-number>
          </el-form-item>
        </el-card>
      </el-form>
      <span slot="footer"
            class="dialog-footer">
        <el-button type="success"
                   @click="saveDialogDataHandle">项目立项</el-button>
      </span>
    </el-dialog>
    <!-- editDialog 创建项目 END -->
    <!-- editDialog 项目详情 START -->
    <el-dialog title="项目详情"
               :visible.sync="editDialogShow2"
               :close-on-click-modal="false"
               :close-on-press-escape="false"
               width="80%">
      <h4>过程记录</h4>
      <e-table :data="processRecordData"
               :columns="columns2"
               :pageShow="false"
               stripe
               border
               :maxHeight="tableMaxHeight"
               style="width: 100%">
        <template slot-scope="{scope}" slot="remark">
          <el-popover placement="top" trigger="hover">
            <div class="cell-content">{{scope.row.remark}}</div>
            <p class="overflow" slot="reference">{{scope.row.remark}}</p>
          </el-popover>
        </template>
      </e-table>
      <el-row style="margin:10px 0">
        <h4 class="borderB">项目基本信息</h4>
        <el-col :span="12"
                class="pd5 lineHeight20">
          <el-col :span="8"
                  class="text-right">项目名称：</el-col>
          <el-col :span="16">
            <template>
              <el-popover placement="top" trigger="hover">
                <div class="cell-content">{{projectData.projectName}}</div>
                <p class="overflow" slot="reference">{{projectData.projectName}}</p>
              </el-popover>
            </template>
          </el-col>
        </el-col>
        <el-col :span="12"
                class="pd5 lineHeight20">
          <el-col :span="8"
                  class="text-right">项目编号：</el-col>
          <el-col :span="16">{{projectData.projectNo}}</el-col>
        </el-col>
        <el-col :span="12"
                class="pd5 lineHeight20">
          <el-col :span="8"
                  class="text-right">询价开始时间：</el-col>
          <el-col :span="16">{{projectData.startTime | formeTime}}</el-col>
        </el-col>
        <el-col :span="12"
                class="pd5 lineHeight20">
          <el-col :span="8"
                  class="text-right">询价结束时间：</el-col>
          <el-col :span="16">{{projectData.endTime | formeTime}}</el-col>
        </el-col>
        <el-col :span="12"
                class="pd5 lineHeight20">
          <el-col :span="8"
                  class="text-right">项目状态：</el-col>
          <el-col :span="16">{{projectData.projectStateCName}}</el-col>
        </el-col>
        <el-col :span="12"
                class="pd5 lineHeight20" v-if="projectData.projectState === '00026_5'">
          <el-col :span="8"
                  class="text-right">询价失败原因：</el-col>
          <el-col :span="16">
            <template>
              <el-popover placement="top" trigger="hover">
                <div class="cell-content">{{projectData.invalidRemark}}</div>
                <p class="overflow" slot="reference">{{projectData.invalidRemark}}</p>
              </el-popover>
            </template>
          </el-col>
        </el-col>
        <el-col :span="12"
                class="pd5 lineHeight20">
          <el-col :span="8"
                  class="text-right">定标状态：</el-col>
          <el-col :span="16">{{projectData.picketageStateCName}}</el-col>
        </el-col>
        <el-col :span="12"
                class="pd5 lineHeight20">
          <el-col :span="8"
                  class="text-right">总预算（元）：</el-col>
          <el-col :span="16">{{projectData.sumPrice}}</el-col>
        </el-col>
        <el-col :span="12"
                class="pd5 lineHeight20">
          <el-col :span="8"
                  class="text-right">项目描述：</el-col>
          <el-col :span="16">
            <template>
              <el-popover placement="top" trigger="hover">
                <div class="cell-content">{{projectData.projectRemark}}</div>
                <p class="overflow" slot="reference">{{projectData.projectRemark}}</p>
              </el-popover>
            </template>
          </el-col>
        </el-col>
      </el-row>
      <!-- 采购人未定标不展示定标信息 -->
      <div v-if="bidPicketageData.picketageState !=='00029_0'">
        <el-row style="margin:10px 0">
          <h4 class="borderB">定标信息</h4>
          <el-col :span="12"
                  class="pd5 lineHeight20">
            <el-col :span="8"
                    class="text-right">{{bingModeLabel}}：</el-col>
            <el-col :span="16">{{isMinPrice(bidPicketageData.isMinPrice)}}</el-col>
          </el-col>
          <el-col :span="12"
                  class="pd5 lineHeight20">
            <el-col :span="8"
                    class="text-right">定标时间：</el-col>
            <el-col :span="16">{{bidPicketageData.createTime | formeTime}}</el-col>
          </el-col>
          <el-col :span="24"
                  class="pd5 lineHeight20">
            <el-col :span="4"
                    class="text-right">采购人说明：</el-col>
            <el-col :span="20">
              <template>
                <el-popover placement="top" trigger="hover">
                  <div class="cell-content">{{bidPicketageData.purchaseRemark}}</div>
                  <p class="overflow" slot="reference">{{bidPicketageData.purchaseRemark}}</p>
                </el-popover>
              </template>
            </el-col>
          </el-col>
          <el-col :span="24"
                  class="pd5 lineHeight20">
            <el-col :span="4"
                    class="text-right">中心审核说明：</el-col>
            <el-col :span="20">
              <template>
                <el-popover placement="top" trigger="hover">
                  <div class="cell-content">{{bidPicketageData.ageinsRemark}}</div>
                  <p class="overflow" slot="reference">{{bidPicketageData.ageinsRemark}}</p>
                </el-popover>
              </template>
            </el-col>
          </el-col>
          <el-col :span="12"
                  class="pd5 lineHeight20"
                  v-if="bidPicketageData.picketageApplyCompleteSourceId">
            <el-col :span="8"
                    class="text-right">定标申请表下载：</el-col>
            <el-col :span="16">
              <el-button style="padding: 0 !important;" type="text" @click="exportAppleForm(bidPicketageData.picketageApplyCompleteSourceId)">{{ appleFileName }}</el-button>
            </el-col>
          </el-col>
        </el-row>
      </div>

      <el-row style="margin:10px 0">
        <h4 class="borderB">询价规则</h4>
        <div v-for="(item,index) in biddingData" :key="index">
          <el-col :span="12"
                  class="pd5 lineHeight20">
            <el-col :span="8"
                    class="text-right">{{item.controlName}}：</el-col>
            <el-col :span="16">{{item.detailName}}</el-col>
          </el-col>
        </div>
      </el-row>
      <h4>报价列表</h4>
      <e-table :data="quotedPriceData"
               :columns="columns3"
               stripe
               border
               :maxHeight="tableMaxHeight"
               style="width: 100%"
               :pageShow="false">
      </e-table>
    </el-dialog>
    <!-- editDialog 项目详情 END -->
    <!-- editDialog 退回弹窗 START -->
    <el-dialog title="请填写退回说明"
               :visible.sync="returnShow"
               :close-on-click-modal="false"
               :close-on-press-escape="false"
               width="50%">
      <el-form :model="returnForm"
               :rules="returnRules"
               ref="returnForm"
               label-width="100px">
        <el-form-item label="退回说明"
                      prop="explain">
          <el-input type="textarea"
                    show-word-limit
                    maxlength="1000"
                    v-model="returnForm.explain"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer"
            class="dialog-footer">
        <el-button type="primary"
                   @click="saveReturntHandle">确认</el-button>
        <el-button type="info"
                   @click="cancelReturnHandle">取消</el-button>
      </span>
    </el-dialog>
    <!-- editDialog 退回弹窗 END -->
    <!-- 查看附件   -->
    <el-dialog :visible.sync="attachmentVisible">
      <img width="100%" :src="dialogImageUrl" alt="">
    </el-dialog>
  </div>
</template>

<script>
import eControl from '@/components/e-control'
import { getDemandList, returnOrder, createProProjects, getOrderDetail, getDetailsByOrderId, getQueryProProcessCodeList, getProProjectInfo, getProjectAndPicketageInfo, getBiddingRules, getBidBiddingPageList } from '@/api/admin.api'
import { queryDictionaryList, getFileInfo, downloadFile } from '@/api/common.api'
import { formOptions } from './control'
import moment from 'moment'
import { columns, columns1, columns2, columns3 } from './columns'
export default {
  name: 'entrusted-manager',
  components: {
    eControl
  },
  props: {
  },
  data () {
    return {
      dialogImageUrl:'',
      attachmentVisible:false,
      // 表格表头
      columns,
      // 上下架记录表格表头
      columns1,
      // 过程化记录
      columns2,
      // 报价列表
      columns3,
      // 表单配置项
      formOptions,
      searchLabelWidth: '100px',
      // 提交表单数据
      formData: {
        bidNumber: 0,
        bidMinNumber: 1
      },
      // 表单校验
      formRules: {
        projectName: [
          { required: true, message: '请输入项目名称', trigger: 'blur' }
        ],
        budget: [
          { required: true, message: '询价预选显示控制不能为空', trigger: 'blur' }
        ],
        price: [
          { required: true, message: '询价者价格显示控制不能为空', trigger: 'blur' }
        ],
        pattern: [
          { required: true, message: '询价模式不能为空', trigger: 'blur' }
        ],
        bidNumber: [
          { required: true, message: '报价次数控制不能为空', trigger: 'blur' }
        ],
        endEnterTime: [
          { required: true, message: '报名截止日期不能为空', trigger: 'blur' }
        ],
        time: [
          { required: true, message: '时间不能为空', trigger: 'blur' }
        ],
        bidMinNumber: [
          { required: true, message: '参加供应商最低家数', trigger: 'blur' }
        ]
      },
      // 管理委托表格数据
      tableData: [],
      // 管理委托是否展示
      editDialogShow: false,
      // 管理委托数据
      orderStateData: {},
      // 管理委托分页数据
      orderStatePageData: {
        // 当前分页
        current: 1,
        // 分页条数
        size: 10,
        // 数据总数
        total: 0
      },

      // 委托购买商品列表数据
      orderStateDetailsData: [],
      // 委托购买商品分页数据
      detailsPageData: {
        // 当前分页
        current: 1,
        // 分页条数
        size: 10,
        // 数据总数
        total: 0
      },

      // 创建项目是否展示
      editDialogShow1: false,
      //  时间为开始之前
      pickerOptions: {
        disabledDate (time) {
          return time.getTime() < Date.now() - 8.64e7
        }
      },
      // 项目详情
      editDialogShow2: false,
      // 过程记录列表数据
      processRecordData: [],
      // 项目基本信息数据:
      projectData: {},
      // 定标信息数据
      bidPicketageData: {},
      // 询价规则数据
      biddingData: [],
      // 报价列表数据
      quotedPriceData: [],
      // 退回弹窗是否展示
      returnShow: false,
      // 退回表单数据
      returnForm: {},
      // 表单校验
      returnRules: {
        explain: [
          { required: true, message: '请输入退回说明', trigger: 'blur' }
        ]
      },
      // 编辑框表单数据
      dialogFormCurrent: {},
      // 查询表单
      searchFormData: {
        purchaseType: 2
      },
      // 控制区高度
      controlHeight: 0,
      // 表格选中数据
      tableSelectData: [],
      // 定标申请表名称
      appleFileName:'',
      // 竞拍模式
      bingMode: {},
      bingModeLabel:''
    }
  },
  watch: {
    bingMode (val) {
      if (Object.keys(val).length > 0) {
        if (val.detailName.indexOf('正拍') != -1) {
          this.bingModeLabel = '是否最高价中标'
        } else if(val.detailName.indexOf('反拍') != -1){
          this.bingModeLabel = '是否最低价中标'
        } else {
          this.bingModeLabel = ''
        }
      }
    }
  },
  filters: {
    formeTime (val) {
      return val ? moment(val).format('YYYY-MM-DD HH:mm:ss') : ' '
    },
    formatFile(value) {
      if (value !== null && value !== undefined && value) {
        const objItem = JSON.parse(value)
        return objItem.name
      } else {
        return ''
      }
    }
  },
  computed: {
    // 表单实例
    dialogForm () {
      return this.$refs.dialogForm
    },
    //表格最大高度
    tableMaxHeight () {
      return window.innerHeight - this.controlHeight - 160
    },
    isMinPrice () {
      return function (val) {
        if (val === '0') {
          return '否'
        } else if (val === '1') {
          return  '是'
        } else {
          return ''
        }
      }
    }
  },
  methods: {
    /**
     * @description 申请表名称
     * @author 穆宏宇
     * @date 2020-11-13 10:28:42
     * @param
     * @return
     * */
    getAppleFileName (value) {
      const objItem = JSON.parse(value)
      // 获取附件信息
      getFileInfo(objItem.fileType,objItem.id).then(res=>{
        this.appleFileName = res.submittedFileName
      })
    },
    /**
     * @description 导出定标申请表
     * @author 穆宏宇
     * @date 2020-11-13 09:46:43
     * @param
     * @return
     * */
    exportAppleForm (jsonComment) {
      const objFile = JSON.parse(jsonComment)
      getFileInfo(objFile.fileType,objFile.id).then(res=>{
        const fileName = res.submittedFileName
        downloadFile(objFile.fileType,objFile.id).then(resBlob=>{
          const blob = new Blob([resBlob], {
            type: 'application/msword'
          })
          this.saveAs(blob, fileName)
        })
      })
    },
    saveAs(blob, filename) {
      if (window.navigator.msSaveOrOpenBlob) {
        navigator.msSaveBlob(blob, filename)
      } else {
        const link = document.createElement('a')
        const body = document.querySelector('body')
        link.href = window.URL.createObjectURL(blob)
        link.download = filename
        link.style.display = 'none'
        body.appendChild(link)
        link.click()
        body.removeChild(link)
        window.URL.revokeObjectURL(link.href)
      }
    },
    // 预览附件
    clickHandlePreview (value) {
      if (value !== null && value !== undefined && value) {
        const objItem = JSON.parse(value)
        // 获取附件信息
        getFileInfo(objItem.fileType,objItem.id).then(res=>{
          if (['image/png','image/jpeg'].includes(res.contextType)) {
            this.dialogImageUrl = res.url
            this.attachmentVisible = true
          } else {
            // 下载
            document.location.href = res.url
          }
        })
      }
    },
    // 查询委托状态option
    queryOrderStateListFn () {
      const param = { dictionaryType: 'order_state', dictionaryKey1: 'order', dictionaryKey3: 'purchase' }
      queryDictionaryList(param).then((res) => {
        res.map((item, index) => {
          const optionObj = {}
          optionObj.label = item.optional3
          optionObj.value = item.code
          this.$set(this.formOptions[2].options, index, optionObj)
        })
      })
    },
    init () {
      this.getTableData()
    },
    // 查询参数
    searchControlHandle (data) {
      const newData = {
        purchaseType: 2,
        orderName: data.orderName,
        purchaseName: data.purchaseName,
        orderState: data.orderState,
        projectNo: data.projectNo,
        startTime: data.date[0],
        endTime: data.date[1]
      }
      this.searchFormData = { ...newData }
      this.orderRefreshPageCurrent()
    },
    // 重置查询条件
    refreshControlHandle (data) {
      this.searchFormData = data
    },
    // 控制查询高度
    changeControlHeight (height) {
      this.controlHeight = height
    },
    // 委托列表修改分页条数
    orderChangePageSize (size) {
      this.orderStatePageData.size = size
      this.getTableData()
    },
    // 委托列表修改当前分页
    orderChangePageCurrent (current) {
      this.orderStatePageData.current = current
      this.getTableData()
    },
    // 委托列表重置分页
    orderRefreshPageCurrent () {
      this.orderStatePageData.current = 1
      this.getTableData()
    },
    // 获取委托列表数据
    getTableData () {
      const newSearchData = { ...this.searchFormData, ...this.orderStatePageData }
      getDemandList(newSearchData).then(res => {
        const filter = this.$options.filters['formeTime']
        const newArr = []
        res.records.map(item => {
          item.updateTime = filter(item.updateTime)
          newArr.push(item)
        })
        this.$nextTick(() => {
          this.tableData = newArr
          this.orderStatePageData.total = res.total
        })
      })
    },
    // 委托购买商品列表改分页条数
    detailsChangePageSize (size) {
      this.orderStatePageData.size = size
      this.getTableData()
    },
    // 委托购买商品列表当前分页
    detailsChangePageCurrent (current) {
      this.orderStatePageData.current = current
      this.getTableData()
    },
    // 委托购买商品列表重置分页
    detailsRefreshPageCurrent () {
      this.orderStatePageData.current = 1
      this.getTableData()
    },
    // 获取管理委托详情
    editTableHandle (row) {
      const self = this
      // 获取过程记录信息
      getQueryProProcessCodeList({ sourceIds: row.id + ',' + row.projectId }).then(res => {
        this.processRecordData = res
      })
      getOrderDetail(row.id).then(res => {
        self.orderStateData = res
        // 获取委托购买商品列表数据
        getDetailsByOrderId(row.id).then(res => {
          self.orderStateDetailsData = res
          self.detailsPageData.total = res.total
          self.editDialogShow = true
        })
      })
    },
    // 关闭弹窗
    closeDialog () {
      this.editDialogShow = false
    },
    // 保存项目
    saveDialogDataHandle () {
      const newFormData = {
        fkEntrustsId: this.orderStateData.id,
        projectName: this.formData.projectName,
        biddingModel: this.formData.budget + ',' + this.formData.price + ',' + this.formData.pattern,
        bidNumber: this.formData.bidNumber,
        endEnterTime: this.formData.endEnterTime,
        startTime: this.formData.time ? this.formData.time[0] : '',
        endTime: this.formData.time ? this.formData.time[1] : '',
        projectRemark: this.formData.projectRemark,
        bidMinNumber: this.formData.bidMinNumber
      }
      this.$refs['editForm'].validate((valid) => {
        if (valid) {
          createProProjects(newFormData).then(res => {
            this.editDialogShow1 = false
            this.editDialogShow = false
            this.$refs['editForm'].resetFields()
            this.$message({
              message: '保存成功',
              type: 'success'
            })
            // 刷新列表数据
            this.getTableData()
          })
        }
      })
    },
    // 创建项目弹窗
    createProjectHandle () {
      this.$set(this.formData,'projectName',this.orderStateData.orderName)
      this.editDialogShow1 = true
      // this.dialogForm.handleRefresh()
      // this.closeDialog()
    },
    // 退回项目弹窗
    returnOrderHandle () {
      this.returnShow = true
    },
    // 提交退回项目说明
    saveReturntHandle () {
      const that = this
      this.$refs['returnForm'].validate((valid) => {
        if (valid) {
          returnOrder(this.orderStateData.id, this.returnForm).then((res) => {
            this.$message({
              message: '已退回',
              type: 'success'
            })
            that.cancelReturnHandle()
            that.closeDialog()
            this.getTableData()
          })
        } else {
          return false
        }
      })
    },
    // 关闭项目说明弹窗
    cancelReturnHandle () {
      this.returnShow = false
      this.$refs['returnForm'].resetFields()
    },
    //
    // 项目详情弹窗
    detailsControlHandle (row) {
      // 获取过程记录信息
      getQueryProProcessCodeList({ sourceIds: row.id + ',' + row.projectId }).then(res => {
        this.processRecordData = res
      })
      // 获取项目基本信息
      getProProjectInfo(row.projectId).then(res => {
        this.projectData = res
      })
      // 获取定标信息
      getProjectAndPicketageInfo({ projectId: row.projectId }).then(res => {
        this.bidPicketageData = res
        if (res.picketageApplyCompleteSourceId) {
          this.getAppleFileName(res.picketageApplyCompleteSourceId)
        }
      })
      // 获取询价规则
      getBiddingRules(row.projectId).then(res => {
        this.biddingData = res
        const arr = res.filter(item => item.controlName === '竞拍模式')
        this.bingMode = arr.length > 0 ? arr[0] : {}
      })
      // 获取报价列表
      const projects = { fkProProjectsId: row.projectId }
      getBidBiddingPageList(projects).then(res => {
        this.quotedPriceData = res.records
      })
      this.editDialogShow2 = true
    }

  },
  created () { },
  mounted () {
    this.queryOrderStateListFn()
    this.init()
  }
}
</script>
<style lang="scss" scoped>
.control-box {
  margin-bottom: 10px;
}
.text-right {
  text-align: right;
}
.pd5 {
  padding: 5px;
}
h4 {
  line-height: 30px;
}
.borderB {
  border-bottom: 1px solid #ccc;
}
.lineHeight20 {
  line-height: 20px;
}
.table-box {
  .el-button {
    margin-bottom: 5px;
  }
}
.cell-content {
  width: 200px;
  min-height: 20px;
  max-height: 200px;
  overflow-y: auto;
}
.overflow {
  width: 118px;
  overflow:hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  -o-text-overflow:ellipsis;
  overflow: hidden;
}
</style>

<style lang="css">

.el-tooltip__popper,.el-tooltip__popper.is-dark{
  background: #FFFFFF;
  max-width: 400px;
  border-radius: 4px;
  border: 1px solid #e6ebf5;
  padding: 12px;
  color: black;
  line-height: 180%;
  -webkit-box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
.el-tooltip__popper[x-placement^=top] .popper__arrow {
  /*border-top-color: rgba(0,0,0,0.4);*/
  bottom: -6px;
  left: 50%;
  margin-right: 3px;
  border-top-color: #FFFFFF;
  border-bottom-width: 0;
  -webkit-filter: drop-shadow(0 2px 12px rgba(0, 0, 0, 0.03));
  filter: drop-shadow(0 2px 12px rgba(0, 0, 0, 0.03));
}
.el-tooltip__popper[x-placement^=top] .popper__arrow:after {
  /*border-top-color: rgba(0,0,0,0.4);*/
  position: absolute;
  display: block;
  width: 0;
  height: 0;
  border-color: transparent;
  border-style: solid;
  /*filter:alpha(opacity=50);
  -moz-opacity:0.5;
  -khtml-opacity: 0.5;
  opacity: 0.5;*/
}
</style>
